package Ms.controller;

import Result.Result;
import cn.dev33.satoken.annotation.SaCheckLogin;



import cn.dev33.satoken.stp.StpUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

// AuthController.java
@RestController
@RequestMapping("/admin/auth")
public class AuthController {
    @PostMapping("/login")
    public Result login(@RequestParam String username,
                        @RequestParam String password) {
        // 1. 校验管理员账号白名单
        if (!"admin001".equals(username)) {
            return Result.error("非管理员账号");
        }

        // 2. Sa-Tsuccessen登录认证
        StpUtil.login(username);
        return Result.success(StpUtil.getTokenInfo());
    }

    @SaCheckLogin
    @PostMapping("/logout")
    public Result logout() {
        StpUtil.logout();
        return Result.success();
    }
}
